//This do file can be used on the 2020 ANES dataset downloaded directly from the ANES website. The purpose of this do file is to clean and rename variables of interest and drop unnecessary variables in order to merge the 2020 and 2016 data files.

*Before running this file, download the dataset directly from ANES, and read it into Stata

generate year =2020

*white identity questions
rename V202499x wid1
rename V202483 wid2
rename V202487 wid3

*demos
rename V201200 ideology 
rename V201231x pid7

generate age = 1 if V201507x == 18 | V201507x == 19 | V201507x == 20
replace age = 2 if V201507x == 21 | V201507x == 22 | V201507x == 23 | V201507x == 24
replace age = 3 if V201507x == 25 | V201507x == 26 | V201507x == 27 | V201507x == 28 | V201507x == 29
replace age = 4 if V201507x == 30 | V201507x == 31 | V201507x == 32 | V201507x == 33 | V201507x == 34
replace age = 5 if V201507x == 35 | V201507x == 36 | V201507x == 37 | V201507x == 38 | V201507x == 39
replace age = 6 if V201507x == 40 | V201507x == 41 | V201507x == 42 | V201507x == 43 | V201507x == 44
replace age = 7 if V201507x == 45 | V201507x == 46 | V201507x == 47 | V201507x == 48 | V201507x == 49
replace age = 8 if V201507x == 50 | V201507x == 51 | V201507x == 52 | V201507x == 53 | V201507x == 54
replace age = 9 if V201507x == 55 | V201507x == 56 | V201507x == 57 | V201507x == 58 | V201507x == 59
replace age = 10 if V201507x == 60 | V201507x == 61 | V201507x == 62 | V201507x == 63 | V201507x == 64
replace age = 11 if V201507x == 65 | V201507x == 66 | V201507x == 67 | V201507x == 68 | V201507x == 69
replace age = 12 if V201507x == 70 | V201507x == 71 | V201507x == 72 | V201507x == 73 | V201507x == 74
replace age = 13 if V201507x >74
tab age

rename V201600 gender
rename V201549x race
rename V201453 religattend
rename V201435 religion

*voting behavior 
generate pres2012vote = 1 if V201105 == 2
replace pres2012vote = 2 if V201105 == 1

label define pres2012vote1 1 "Romney" 2 "Obama" 
label values pres2012vote pres2012vote1

generate pres2016vote = 1 if V201103 == 2
replace pres2016vote = 2 if V201103 == 1

label define pres2016vote1 1 "Trump" 2 "Clinton" 
label values pres2016vote pres2016vote1

generate pres2020vote = 1 if V201029 == 2
replace pres2020vote = 2 if V201029 == 1

label define pres2020vote1 1 "Trump" 2 "Biden" 
label values pres2020vote pres2020vote1

*income
rename V201617x income

*education 
rename V201511x edu

//Issue Indexes

*nationalism 
rename V202421 nationalism1
rename V202422 nationalism2
rename V202423 nationalism3
rename V202424 nationalism4 

*racial resentment questions 
rename V202300 rr1
rename V202301 rr2
rename V202302 rr3
rename V202303 rr4

*immigration 
rename V201427 immigration1
rename V201426x immigration2
rename V201423x immigration3
rename V201420x immigration4

*women
rename V202286x women1
rename V202290x women2
rename V202291 women3
rename V202292 women4

*climate
rename V202332 climate1
rename V202336x climate2

*lgbtq+
rename V201408x lgbtq1
rename V201411x lgbtq2
rename V201414x lgbtq3
rename V201415 lgbtq4

*medical insuarnce 
rename V201252 medinsur

*abortion
rename V201336 abortion

//Generate Operational Ideology

*death penalty
generate deathpen = 1 if V201345x == 1 | V201345x == 2
replace deathpen = -1 if V201345x == 3 | V201345x == 4

*gov make it more difficult to buy a gun
generate gunpurchase = 1 if V202337 == 2
replace gunpurchase = -1 if V202337 == 1
replace gunpurchase = 0 if V202337 == 3

*federal budget spending on welfare
generate welfarespend = 1 if V201312 == 2
replace welfarespend = -1 if V201312 == 1
replace welfarespend = 0 if V201312 == 3

*millionare tax
generate milltax = 1 if V202325 == 2
replace milltax = -1 if V202325 == 1
replace milltax = 0 if V202325 == 3

*treatment 
rename V202490x treat1
rename V202493x treat2

*gov spending for healthcare
generate healthspend = 1 if V202380x == 7 | V202380x == 6 | V202380x == 5
replace healthspend = -1 if V202380x == 1 | V202380x == 2 | V202380x == 3
replace healthspend = 0 if V202380x == 4

//Thermometer Ratings 

*thermometer 
rename V201152 thermtrump
rename V201157 thermrepparty 

keep year wid1 wid2 wid3 ideology pid7 age gender race religattend religion pres2012vote pres2016vote income edu nationalism1 nationalism2 nationalism3 nationalism4 rr1 rr2 rr3 rr4 immigration1 immigration2 immigration3 immigration4 women1 women2 women3 women4 climate1 climate2 lgbtq1 lgbtq2 lgbtq3 lgbtq4 medinsur abortion deathpen gunpurchase welfarespend milltax treat1 treat2 healthspend thermtrump thermrepparty

















